<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8" />
    <title>Loaha CMS</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <link rel="stylesheet" href="/app/laoha/sdk/sdk.css" />
    <link rel="stylesheet" href="/app/laoha/sdk/helper.css" />
    <link rel="stylesheet" href="/app/laoha/sdk/iconfont.css" />
    <style>
        html,
        body,
        .app-wrapper {
            position: relative;
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
        }

        img {
            max-width: 100%;
        }
    </style>
</head>

<body>
    <div id="root" class="app-wrapper"></div>
    <script src="/app/laoha/sdk/sdk.js"></script>
    <script type="text/javascript">
        // API相关常量
        const LIST_API = "/app/laoha/admin/comment/list";
        const CHECK_API = "/app/laoha/admin/comment/check";
        const DELETE_API = "delete:/app/laoha/admin/comment/delete";
        (function () {
            let amis = amisRequire('amis/embed');
            // 通过替换下面这个配置来生成不同页面
            let amisJSON = {
                "type": "page",
                "data": <?= json_encode($params, JSON_UNESCAPED_UNICODE) ?>,
                "title": "评论列表",
                "body": [
                    {
                        "type": "crud",
                        //"syncLocation": false,
                        "api": LIST_API,
                        "headerToolbar": [
                            {
                                "label": "待审核",
                                "type": "button",
                                "actionType": "link",
                                "url": "/app/laoha/admin/comment/index?status=1",
                                "level": "primary",
                                "align": "right",
                                "visibleOn": "${!cur_status}"
                            },
                            {
                                "label": "全部",
                                "type": "button",
                                "actionType": "link",
                                "url": "/app/laoha/admin/comment/index",
                                "level": "primary",
                                "align": "right",
                                "visibleOn": "${cur_status}"
                            },
                            "bulkActions"
                        ],
                        "bulkActions": [
                            {
                                "label": "批量删除",
                                "actionType": "ajax",
                                "api": DELETE_API + "?ids=${ids}",
                                "confirmText": "确定要批量删除?"
                            },
                            {
                                "label": "批量审核",
                                "actionType": "ajax",
                                "api": {
                                    "method": "put",
                                    "url": CHECK_API,
                                    "data": {
                                        "ids": "${ids}",
                                        "status": 0
                                    }
                                },
                                "confirmText": "确定要批量通过审核?"
                            },
                            {
                                "label": "批量待审",
                                "actionType": "ajax",
                                "api": {
                                    "method": "put",
                                    "url": CHECK_API,
                                    "data": {
                                        "ids": "${ids}",
                                        "status": 1
                                    }
                                },
                                "confirmText": "确定要批量处理成待审状态?"
                            }
                        ],
                        "rowClassNameExpr": "<%= data.status ? '' : 'bg-light' %>",
                        //列表
                        "columns": [
                            {
                                "name": "id",
                                "label": "ID",
                                "width": 50,
                                "sortable": true
                            },
                            {
                                "name": "content",
                                "label": "评论",
                                "type": "tpl",
                                "tpl": "<a href='/app/laoha/user/index?user_id=${user_id}' target='_blank'>${user.nickname}</a> <small>于：${created_at}</small> 评论《<a href='/app/laoha/post/detail?id=${root.id}' target='_blank'>${root.title}</a>》<div>${content|raw}</div>"
                            },
                            {
                                "type": "operation",
                                "label": "操作",
                                "width": 100,
                                "fixed": "right",
                                "buttons": [
                                    {
                                        "type": "button",
                                        "icon": "fa fa-check text-danger",
                                        "label": "审核",
                                        "actionType": "ajax",
                                        "confirmText": "您确认此评论通过审核?",
                                        "api": {
                                            "method": "put",
                                            "url": CHECK_API,
                                            "data": {
                                                "id": "${id}",
                                                "status": 0
                                            }
                                        },
                                        //"api": CHECK_API + "?id=${id}&status=0",
                                        "visibleOn": "${status==1}"
                                    },
                                    //删除
                                    {
                                        "type": "button",
                                        "icon": "fa fa-trash text-danger",
                                        "label": "删除",
                                        "actionType": "ajax",
                                        "confirmText": "您确认要删除?",
                                        "api": DELETE_API + "?id=${id}"
                                    },
                                ]
                            }
                        ],
                    }
                ]
            };
            let amisScoped = amis.embed('#root', amisJSON, {}, { toastPosition: 'center' });
        })();
    </script>
</body>

</html>